<link rel="stylesheet" href="__PUBLIC__/js/jquery-upload/css/jquery.fileupload.css" />
<link rel="stylesheet" href="__PUBLIC__/js/jquery-upload/css/jquery.fileupload-ui.css" />
<link rel="stylesheet" href="__PUBLIC__/css/select2/select2.css" />
<link href="__PUBLIC__/css/select2/select2-bootstrap.min.css" rel="stylesheet" />
<div class="modal-dialog" role="document">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="exampleModalLabel">{$pageName}</h4>
        </div>
        <form style="margin:4%;" id="addNewsCateForm" data-toggle="validator" role="form">
            <div class="form-group">
                <label for="cate_name" class="control-label">分类名称:</label>
                <input type="text" class="form-control" name="cate_name" value="{$cateInfo.cate_name}" data-error="分类名称不能为空!" data-minlength="2" required>
                <div class="help-block with-errors"></div>
            </div>
          
           
            <div class="form-group">
                <label for="recipient-name" class="control-label">所属分类:</label>
                <select name="pid" id="cateList">
                    <option value="0">顶级分类</option>
                    <volist name="cateList" id="cate">
                        <option <if condition="$cateInfo['pid'] eq $cate['id']">selected="selected"</if> value="{$cate.id}" parent="{$cate.pid}" >{$cate.cate_name}</option>
                    </volist>
                </select>
            </div>
            
            <div class="form-group">
                <label for="recipient-name" class="control-label">分类图片:</label>
                <img id="userAvatarImg" <if condition="$cateInfo['pic'] neq '' " >src="__ROOT__{$cateInfo.pic}" <else/> src="__PUBLIC__/images/avatar.png" </if>   width='150px' />
                <input id="fileupload" type="file" name="files[]" multiple style="display: none;">
            </div>
            <input type="hidden" name="pic" id="avatar" value="{$cateInfo.pic}" />
            <input type="hidden" name="id" value="{$cateInfo.id}" />
        </form>
        <div class="modal-footer">
            <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
            <button type="button" id="userSave" class="btn btn-primary">保存</button>
        </div>
    </div>
</div>
<script type="text/javascript" src="__PUBLIC__/js/jquery-upload/js/vendor/jquery.ui.widget.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/jquery-upload/js/jquery.fileupload.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/jquery-upload/js/jquery.fileupload-ui.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/jquery-upload/js/jquery.iframe-transport.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/jquery-upload/js/jquery.fileupload-process.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/select2/select2.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/select2tree.js"></script>
<script>
    var ROOTPATH = "__ROOT__";
    $(function () {
        $("#addNewsCateForm").validator();
        $("#cateList").select2tree();
    })
    $("#userAvatarImg").click(function(){
        $('#fileupload').click();
    })
    $('#fileupload').fileupload({
        url: "{:U('Admin/Upload/index')}",
        dataType: "",
        formData: {type: "newscat"},
        autoUpload: true,
        done: function (e, data) {
            var files = data.result;
            var file = files[0];
            $("#userAvatarImg").attr("src",ROOTPATH+file.filePath);
            $("#avatar").val(file.filePath);
        }
    });

    $("#userSave").click(function () {
        var validator = $("#addNewsCateForm").data("bs.validator");
        validator.validate();
        if(!validator.hasErrors()){
            $.ajax({
                url: "{:U('Admin/News/doAddNewsCate')}",
                type: "post",
                dataType: "json",
                data: $("#addNewsCateForm").serialize(),
                success: function (data) {
                    //console.log(data);
                    if(data.status){
                        $("#commonModal").modal('toggle');
                        common.alert("提示", data.msg, function () {
                            common.reload();
                        });
                    }else{
                        common.alert("提示", data.msg)
                    }
                }
            })
        }
    });
</script>